<?php
/*******************************************
* Sphider Version 1.3.x
* This program is licensed under the GNU GPL.
* By Ando Saabas          ando(a t)cs.ioc.ee
********************************************/
//error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); 
error_reporting(E_ALL); 
$include_dir = "./include"; 
include ("$include_dir/commonfuncs.php");
//extract(getHttpVars());

if (isset($_GET['query']))
	$query = $_GET['query'];
if (isset($_GET['search']))
	$search = $_GET['search'];
if (isset($_GET['domain'])) 
	$domain = $_GET['domain'];
if (isset($_GET['type'])) 
	$type = $_GET['type'];
if (isset($_GET['catid'])) 
	$catid = $_GET['catid'];
if (isset($_GET['category'])) 
	$category = $_GET['category'];
if (isset($_GET['results'])) 
	$results = $_GET['results'];
if (isset($_GET['start'])) 
	$start = $_GET['start'];
if (isset($_GET['adv'])) 
	$adv = $_GET['adv'];
	
	
$include_dir = "./include"; 
$template_dir = "./templates"; 
$settings_dir = "./settings"; 
$language_dir = "./languages";


require_once("$settings_dir/database.php");
require_once("$language_dir/en-language.php");
require_once("$include_dir/searchfuncs.php");
require_once("$include_dir/categoryfuncs.php");


include "$settings_dir/conf.php";

echo <<< HERE
<html class="no-js" lang="en">

<head>
	<title>Shopping Cart</title>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;" />
	<meta name="format-detection" content="telephone=no" />

	<link rel="shortcut icon" type="image/ico" href="images/favicon.ico" />
	<link rel="apple-touch-icon" href="images/apple-touch-icon.png" />

	<link rel="stylesheet" href="../css/reset.css" />
	<link rel="stylesheet" href="../css/utils.css" />
	<link rel="stylesheet" href="../css/layout.css" />
	<link rel="stylesheet" href="../css/typography.css" />
	<link rel="stylesheet" href="../css/lists.css" />
	<link rel="stylesheet" href="../css/forms.css" />
	<link rel="stylesheet" href="../css/blocks.css" />
	<link rel="stylesheet" href="../css/media-queries.css" />

	<script src="../js/json2.js"></script>
	<script src="../js/zepto.js"></script>
	<script src="../js/m-trapeze.js"></script>
	<script src="../js/m-carousel.js"></script>
	<script src="../js/m-statusbar.js"></script>

	<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="http://code.google.com/apis/gears/gears_init.js"></script> 
	<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=geometry"></script>
</head>

<body class="home-page">
	<div id="Wrapper">
		<header id="Chrome">
		   
			<div id="Logo"></div>
			<nav id="ChromeNav">
				<ul>
				   <li id="NavHome"><a href="../home.php" class="icon">Home</a></li>
				   <li id="NavLocator"><a href="/locator/search/"><span class="word">Find</span> <span class="word">Locations</span></a></li>
				   
				   <li id="NavSearch"><a href="/search/" class="icon">Search</a></li>
				</ul>
			</nav>

			<form id="FormLocator" action="../choice.php" method="get" class="chrome-block">
				<div class="container">
					<label for="id_location">Enter Zip or City Name</label>
					<div class="wrapper">
						<button id="LocatorCurrent" class="button-primary">Use Curent Location</button>
						<input id="id_location" name="location" type="text"  />
						<input id="id_lat" name="lat" type="hidden" />
						<input id="id_lng" name="lng" type="hidden" />
						<input id="id_geocode_results" name="geocode_results" type="hidden" />
						<button id="LocatorSearch" class="button-secondary" type="submit">Search</button>
					</div>
				</div>
			</form>

			<form id="FormSearch" action="../sphider/search.php" method="get" class="chrome-block">
				<div class="container">
					<label for="id_q">Search QuickMart</label>
					<div class="wrapper">
						<input id="query" name="query"  type="text" />
						<input type="hidden" name="c" id="id_c" />
						<button class="button-secondary" type="submit">Search</button>
					</div>
				</div>
			</form>
		</header>
HERE;
// include "$template_dir/$template/header.html";
include "$language_dir/$language-language.php";


if ($type != "or" && $type != "and" && $type != "phrase") { 
	$type = "and";
}

if (preg_match("/[^a-z0-9-.]+/", $domain)) {
	$domain="";
}


if ($results != "") {
	$results_per_page = $results;
}

if (get_magic_quotes_gpc()==1) {
	$query = stripslashes($query);
} 

if (!is_numeric($catid)) {
	$catid = "";
}

if (!is_numeric($category)) {
	$category = "";
} 



if ($catid && is_numeric($catid)) {

	$tpl_['category'] = sql_fetch_all('SELECT category FROM '.$mysql_table_prefix.'categories WHERE category_id='.(int)$_REQUEST['catid']);
}
	
$count_level0 = sql_fetch_all('SELECT count(*) FROM '.$mysql_table_prefix.'categories WHERE parent_num=0');
$has_categories = 0;

if ($count_level0) {
	$has_categories = $count_level0[0][0];
}



// require_once("$template_dir/$template/search_form.html");


function getmicrotime(){
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
    }



function poweredby () {
	global $sph_messages;
    //If you want to remove this, please donate to the project at http://www.sphider.eu/donate.php
    print $sph_messages['Powered by'];?>  <a href="http://www.sphider.eu/"><img src="sphider-logo.png" border="0" style="vertical-align: middle" alt="Sphider"></a>

    <?php 
}


function saveToLog ($query, $elapsed, $results) {
        global $mysql_table_prefix;
    if ($results =="") {
        $results = 0;
    }
    $query =  "insert into ".$mysql_table_prefix."query_log (query, time, elapsed, results) values ('$query', now(), '$elapsed', '$results')";
	mysql_query($query);
                    
	echo mysql_error();
                        
}

$search = 1;
echo <<< HERE
<div>
	<div id="Content">
		<header class="row">
			<h2>Search Results</h2>
		</header>
HERE;
switch ($search) {
	case 1:

		if (!isset($results)) {
			$results = "";
		}
		$search_results = get_search_results($query, $start, $category, $type, $results, $domain);
		require("$template_dir/$template/search_results.html");
	break;
	default:
		if ($show_categories) {
			if ($_REQUEST['catid']  && is_numeric($catid)) {
				$cat_info = get_category_info($catid);
			} else {
				$cat_info = get_categories_view();
			}
			//require("$template_dir/$template/categories.html");
		}
	break;
	}
echo "</div>";
// include "$template_dir/$template/footer.html";
include "../footer.php";
?>
